package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.utils.ResultUtils;
import com.rules.admin.entity.ValidatorModel;
import com.rules.admin.service.ValidatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping({"/validator"})
@Controller
public class ValidatorController {
   @Autowired
   private ValidatorService validatorService;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<ValidatorModel> queryPage(ValidatorModel validatorModel, IPage<ValidatorModel> page) {
      return this.validatorService.queryPage(validatorModel, page);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addValidator(@RequestBody ValidatorModel validatorModel) {
      this.validatorService.save(validatorModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getValidator(@PathVariable("id") String id) {
      ValidatorModel validatorModel = (ValidatorModel)this.validatorService.getById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData(validatorModel);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteValidator(@PathVariable("id") String id) {
      this.validatorService.removeById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateDubbo(@RequestBody ValidatorModel validatorModel) {
      this.validatorService.save(validatorModel);
      return ResultUtils.getSuccessResultData();
   }
}
